﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;

namespace IntelligentCMS
{
    public partial class userprofile : System.Web.UI.Page
    {
        private long userid = -1;

        protected void Page_Load(object sender, EventArgs e)
        {

            if (Session["UserID"] == null)
            {
                Response.Redirect("login.aspx");
            }

            userid = (long)Session["UserID"];
            loadProfile();
           
            

        }

        protected void updateProfile(object sender, EventArgs e)
        {
            CMSDataLayer.UpdateProfile(userid, userfirstname.Text, userlastname.Text, useraddress.Text, usercity.Text, userstate.Text, userzip.Text, usercountry.Text, usercellphone.Text, userworkphone.Text, userhomephone.Text);

            success.Text = "Your user profile has successfully been updated";
        }

        protected void loadProfile()
        {
            DataTable p = CMSDataLayer.GetProfile(userid);
            DataTable u = CMSDataLayer.GetUsernameFromUserID(userid);

            userusername.Text = common.FromBase64String(u.Rows[0][0].ToString());

            userfirstname.Text = common.FromBase64String(p.Rows[0][0].ToString());
            userlastname.Text = common.FromBase64String(p.Rows[0][1].ToString());
            useraddress.Text = common.FromBase64String(p.Rows[0][2].ToString());
            usercity.Text = common.FromBase64String(p.Rows[0][3].ToString());
            userstate.Text = common.FromBase64String(p.Rows[0][4].ToString());
            userzip.Text = common.FromBase64String(p.Rows[0][5].ToString());
            usercountry.Text = common.FromBase64String(p.Rows[0][6].ToString());
            usercellphone.Text = common.FromBase64String(p.Rows[0][7].ToString());
            userworkphone.Text = common.FromBase64String(p.Rows[0][8].ToString());
            userhomephone.Text = common.FromBase64String(p.Rows[0][9].ToString());
        }
    }
}
